package com.example.jolly_sonlocal.zyfypt_513cfr.fragement;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;


import com.example.jolly_sonlocal.zyfypt_513cfr.R;
import com.example.jolly_sonlocal.zyfypt_513cfr.adapter.articleadapter;
import com.example.jolly_sonlocal.zyfypt_513cfr.bean.ArticleBean;
import com.example.jolly_sonlocal.zyfypt_513cfr.iface.Articlelistener;
import com.example.jolly_sonlocal.zyfypt_513cfr.model.ArticleModer;

import java.util.List;

/**
 * Created by zci on 2017/5/23.
 */

public class articlefragement extends Fragment {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private articleadapter myadapter;
    private List<ArticleBean> list=null;
    private View view=null;
    private Context context;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        view=inflater.inflate(R.layout.articlefragement,container,false);
        context=view.getContext();

        initRecyclerView();
        ArticleModer articleModel =new ArticleModer();
        articleModel.getResultList("article",2,"oeau24oa0naqqeglc0ec7j2bp0",articleListener);
        return view;
    }
    Articlelistener articleListener =new Articlelistener() {
        @Override
        public void onResponse(List<ArticleBean> listbean) {

            list = listbean;
            myadapter.setList(list);

        }
        @Override
            public void onFail(String msg){
                Toast.makeText(context, "fail:" + msg, Toast.LENGTH_SHORT).show();
            }
        };

        private void initRecyclerView() {
            recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);

            //创建默认的线性LayoutManager
            layoutManager = new LinearLayoutManager(context);
            //设置布局
            recyclerView.setLayoutManager(layoutManager);
            //设置item的高度
            recyclerView.setHasFixedSize(true);
            //创建适配器
//        list=getData();
            myadapter= new articleadapter(context);

           myadapter.setList(list);

            recyclerView.setAdapter(myadapter);

        }
}
